--颂歌
local songge = fk.CreateSkill {
    name = "mcdh_songge",
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

songge:addEffect(fk.EventPhaseStart,{
    can_trigger = function(self, event, target, player, data)
        local room = player.room
        return target.phase == Player.Finish and  player:hasSkill(self)
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        --num 满足的项数
        local num = 0
        if not target:isWounded() then
            num = num+1
        end
        local events = room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
            local use = e.data
            return table.contains(use:getAllTargets(),target)
        end, Player.HistoryTurn)

        if #events ~= 1  then
            num = num + 1
        end

        if #room.logic:getActualDamageEvents(1, function(e) return e.data.from == target end) == 1 then
            num = num + 1
        end
        self.cost_data = num
        if num == 0  then
            return false
        end
        if num == 2 and not  player:isWounded() then
            return false
        end
        if num == 3 and player:getMark("mcdh_charge_max") - target:getMark("mcdh_charge") <= 0 then
            return false
        end
        return room:askForSkillInvoke(target, self.name, data, "#mcdh_songge:"..player.id.."::"..num)
    end,
    on_use = function(self, event, target, player, data)
        local room =player.room
        local num = self.cost_data
        if num == 1 then
            local check = U.askForUseVirtualCard(room, player, "fire_attack", nil, self.name, "#mcdh_xinghuo-use")
            if not check then
                player:drawCards(1,self.name)
            end
        elseif num == 2 then
            room:recover({
                who = player,
                num = 1,
                recoverBy = player,
                skillName = self.name,
            })
        elseif num == 3 then
            lib.RecoverCharge(player,player,2,self.name)
        end
    end
})

Fk:loadTranslationTable {
    ["mcdh_songge"] = "颂歌",
    [":mcdh_songge"] = "每名角色的结束阶段,其可以令你执行 〖星火〗的第X项(X为其满足的选项数):1.未受伤;2.本回合未成为过牌的目标;3.本回合造成过伤害。",
    ["#mcdh_songge"] = "颂歌:令 %src 执行 【星火】的第 %arg 项",
}

return songge